package com.photoeditor.demo.ui.adapter.share;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.photoeditor.R;
import com.photoeditor.demo.app.BaseRecycleViewAdapter;
import com.photoeditor.demo.model.bean.IItemBean;
import com.photoeditor.demo.ui.widget.share.ShareImageItem;
import com.photoeditor.demo.util.FontUtil;

/**
 * Created by Administrator on 2017/5/22 0022.
 */

public class ShareImageAdapter extends BaseRecycleViewAdapter<IItemBean> {

    protected static final int TYPE_CONTENT = 0;

    @Override
    protected RecyclerView.ViewHolder createVHolder(ViewGroup parent, int viewType) {
        RecyclerView.ViewHolder viewHolder = null;
        switch (viewType) {
            case TYPE_CONTENT:
                LayoutInflater inflater = LayoutInflater.from(parent.getContext());
                View layout = inflater.inflate(R.layout.item_share_image, null, false);
                viewHolder = new ShareImageViewHolder(layout);
                break;
        }

        return viewHolder;
    }

    @Override
    public int getItemViewType(int position) {
        int type = TYPE_CONTENT;
        return type;
    }

    @Override
    protected void showItemView(RecyclerView.ViewHolder holder, int position) {
        int viewType = getItemViewType(position);
        IItemBean itemBean = mData.get(position);
        switch (viewType) {
            case TYPE_CONTENT: {
                ShareImageViewHolder viewHolder = (ShareImageViewHolder) holder;
                ShareImageItem.ShareImageItemData bean = ((ShareImageItemDataBean) itemBean).get();
                viewHolder.mShareIcon.setImageDrawable(bean.getmIcon());
                viewHolder.mShareLabel.setText(bean.getmLabel());
                if (getItemCount() > 8) {
                    viewHolder.mShareLabel.setVisibility(View.VISIBLE);
                } else {
                    viewHolder.mShareLabel.setVisibility(View.GONE);
                }
                break;
            }
        }
    }

    @Override
    public long getAdapterItemId(int position) {
        return position;
    }

    private class ShareImageViewHolder extends RecyclerView.ViewHolder {

        public ImageView mShareIcon;
        public TextView mShareLabel;

        public ShareImageViewHolder(View itemView) {
            super(itemView);
            mShareIcon = (ImageView) itemView.findViewById(R.id.share_icon);
            mShareLabel = (TextView) itemView.findViewById(R.id.share_label);
            FontUtil.setCustomFont(mShareLabel);
        }
    }

    public static class ShareImageItemDataBean implements IItemBean<ShareImageItem.ShareImageItemData> {
        private ShareImageItem.ShareImageItemData shareImageItemData;

        @Override
        public ShareImageItem.ShareImageItemData get() {
            return shareImageItemData;
        }

        @Override
        public void set(ShareImageItem.ShareImageItemData data) {
            shareImageItemData = data;
        }

        @Override
        public int getType() {
            return 0;
        }

        @Override
        public void setType(int type) {

        }

        @Override
        public int getDataCount() {
            return 0;
        }
    }
}
